// 导入
import instance from '@/utils/axios.js'

// 频道接口
const getChannels = () => {
    return instance({
        url: '/v1_0/user/channels',
        method: 'get',
    })
}

// 频道接口
const getArticles = ({ channel_id, timestamp }) => {
    return instance({
        url: '/v1_1/articles',
        method: 'get',
        params: {
            with_top: 1, //是否需要置顶，给1即可
            channel_id,
            timestamp
        }
    })
}

// 文章详情接口
const getArticlesinfo = ({ id }) => {
    return instance({
        url: '/v1_0/articles/' + id,
        method: 'get',
    })
}

// 关注用户接口
const fellowUser = ({ target }) => {
    return instance({
        url: '/v1_0/user/followings',
        method: 'post',
        data: { target }
    })
}

// 取消用户接口
const unFollowUser = ({ target }) => {
    return instance({
        url: '/v1_0/user/followings/' + target,
        method: 'delete',
    })
}
// 导出接口
export { fellowUser, unFollowUser }


// 搜索联想
const getSuggestion = ({ q }) => {
    return instance({
        url: '/v1_0/suggestion',
        method: 'get',
        params: {
            q
        }
    })
}

// 点赞文章接口
const likingsUser = ({ target }) => {
    return instance({
        url: '/v1_0/article/likings',
        method: 'post',
        data: {
            target
        }
    })
}
// 导出接口
export { likingsUser }

// 取消点赞文章
const cancelLikings = ({ target }) => {
    return instance({
        url: '/v1_0/article/likings/' + target,
        method: 'delete',
    })
}
// 导出取消点赞接口
export { cancelLikings }
// 对文章不喜欢
const dislikesArticle = ({ target }) => {
    return instance({
        url: '/v1_0/article/dislikes',
        method: 'post',
        data: { target }
    })
}
export { dislikesArticle }

// 取消对文章不喜欢
const canccelDislikes = ({ target }) => {
    return instance({
        url: '/v1_0/article/dislikes/' + target,
        method: 'delete'
    })
}
export { canccelDislikes }

// 搜索历史
// 导入token
import { getToken } from '@/utils/token.js'
const searchHistory = () => {
    return instance({
        url: '/v1_0/search/histories',
        method: 'get',
        headers: {
            Authorization: `Bearer ${getToken().token}`
        }
    })
}
export { searchHistory }

// 删除历史记录
const delHistories = () => {
    return instance({
        url: '/v1_0/search/histories',
        method: 'delete',
    })
}
// 导出接口
export { delHistories }
// 获取搜索内容
const getSeach = (params) => {
    return instance({
        url: '/v1_0/search',
        method: 'get',
        params
    })
}
export { getSeach }

// tab栏接口
export { getChannels }
//文章列表
export { getArticles }
// 文章详情
export { getArticlesinfo }
// 搜索联想
export { getSuggestion }
